from tortoise import Tortoise
from app.core.config import settings

async def init_db():
    """初始化数据库连接"""
    await Tortoise.init(
        db_url=settings.DB_URL,
        modules={"models": ["app.models.models", "app.models.log_models"]},
    )
    # 生成数据库表结构
    await Tortoise.generate_schemas()

async def close_db():
    """关闭数据库连接"""
    await Tortoise.close_connections()